
IF (NOT EXISTS (SELECT name
                FROM master.dbo.sysdatabases
                WHERE name = 'FStore_DB'))
BEGIN
Create Database FStore_DB
 on 
  ( name = 'FStore_DB' , filename = 'G:\ThuanPhong.co\FStore project\FStore_Project\Database\FStore_DB.mdf')
 log on
 ( name = 'FStore_DB_LOG' , filename ='G:\ThuanPhong.co\FStore project\FStore_Project\Database\FStore_DB.ldf') 
 END
go
/* Use Database*/
use FStore_DB

/*=====  Create Table   =====*/ 
/*==== Create table Product category =====*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_ProductCategory')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_ProductCategory table...'
create table tbl_ProductCategory(
 ProductCateId int primary key,
 ProductCateName nvarchar(255),
 ProductCateDes nvarchar(1000),
 ProductCateImg nvarchar(255),
 ProductCateType int,
 ProductCateIsActive bit,
)
END
/*===== Create table Product category =====*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_ProductCateIsStore')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_ProductCateIsStore table...'
create table tbl_ProductCateIsStore(
  StoreId uniqueidentifier    NOT NULL PRIMARY KEY NONCLUSTERED FOREIGN KEY REFERENCES dbo.aspnet_Users(UserId),
  ProductCateId int FOREIGN KEY REFERENCES tbl_ProductCategory(ProductCateId)  ,
)
END
/*===== Package table =====*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_Package')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_Package table...'
Create table tbl_Package(
  PackId int primary key,
  PackName nvarchar(255),
  PackDes nvarchar(1000),
  PackImg nvarchar(1000),
  MonthDuration int ,
  NumofProduct int,
)
End
/*===== City ======*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_City')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_City table...'
create table tbl_City(
  CityId int primary key,
  CityName nvarchar(255),
)
END
/*===== Store table =====*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_Store')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_Store table...'
create table tbl_Store(
  StoreId uniqueidentifier    NOT NULL PRIMARY KEY NONCLUSTERED FOREIGN KEY REFERENCES dbo.aspnet_Users(UserId),
  PackId int foreign key references tbl_Package(PackId),
  CityId int foreign key references tbl_City(CityId),
  StoreName nvarchar(255),
  StorePhone char(100),
  StoreAddress nvarchar(1000),
  StoreEmail nvarchar(255),  
  StoreGender nchar(30),
  StoreThemes int,
  IsFristTime bit,
  IsActive bit,
  DateExpiry Datetime,
  DateCreate Datetime,
  StoreType int,
)
End
/*===== Contact Table ======*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_Contact')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_Contact table...'
create table tbl_Contact(
  ContactId bigint primary key,
  StoreId uniqueidentifier    NOT NULL FOREIGN KEY REFERENCES dbo.aspnet_Users(UserId),
  FullName nvarchar(255),
  ContactName nvarchar(255),
  ContactContent nvarchar(1000),
  ContactPhone char(100),
  ContactEmail nvarchar(255),
  DateSend Datetime,
  ContactStatus int,
)
END
/*===== IntroPage table =====*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_IntroPage')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_IntroPage table...'
create table tbl_IntroPage(
  IntroId int primary key,
  StoreId uniqueidentifier    NOT NULL FOREIGN KEY REFERENCES dbo.aspnet_Users(UserId),
  IntroContent nvarchar(max),
  IntroImg nvarchar(255),
  DateCreate Datetime,
)
END
/*===== SubProductCate =====*/
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_SubProductCate')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_SubProductCate table...'
create table tbl_SubProductCate(
 SubProductCateId int primary key,
 ProductCateId int foreign key references tbl_ProductCategory(ProductCateId),
 SubProductCateName nvarchar(255),
 SubProductCateDes nvarchar(1000),
 SubProductCateType int,
 SubProductCateIsActive bit,
)
END
/*===== Product =====*/
go
IF (NOT EXISTS (SELECT name
                FROM sysobjects
                WHERE (name = N'tbl_Product')
                  AND (type = 'U')))
BEGIN
  PRINT 'Creating the tbl_Product table...'
create table tbl_Product(
 ProductId bigint primary key,
 StoreId uniqueidentifier    NOT NULL FOREIGN KEY REFERENCES dbo.aspnet_Users(UserId),
 SubProductCateId int foreign key references tbl_SubProductCate(SubProductCateId),
 ProductName nvarchar(255),
 ProductDes nvarchar(1000),
 ProductImg nvarchar(255),
 ProductSize nvarchar(255),
 ProdcutPrice money,
 ProductGender nchar(30),
 DateCreate Datetime,
)
End
